home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 18 / CU Amiga Magazine's Super CD-ROM 18 (1997)(EMAP Images)(GB)[!][issue 1998-01].iso / CUCD / Programming / AmigaE / Src / Tools / qItemAddress / qualifiedItemAddress.e next >
Text File  |  1994-12-08  |  4KB  |  97 lines

  1. /*----------------------------------------------------------------------------*
  2.  
  3.   EMODULES:other/qualifiedItemAddress
  4.  
  5.     NAME
  6.       qualifiedItemAddress -- processes case-sensitive menu command hotkeys
  7.                               for either shift key
  8.  
  9.     SYNOPSIS
  10.       itemAddress:=qualifiedItemAddress(menuStrip, menuNumber, qualifier)
  11.  
  12.       PROC qualifiedItemAddress(menuStrip:PTR TO menu, menuNumber, qualifier=0)
  13.         DEF itemAddress:PTR TO menuitem
  14.       ENDPROC itemAddress
  15.  
  16.     FUNCTION
  17.       Use of this function is similar to the Intuition routine ItemAddress(),
  18.       with the addition of the qualifier argument.  Both menuNumber and
  19.       qualifier can be obtained from the Intuition IDCMP_MENUPICK message
  20.       received by your program.  menuStrip is searched for the upper- or
  21.       lowercase equivalent menu command hotkey, depending on whether
  22.       qualifier contains IEQUALIFIER_RSHIFT and/or IEQUALIFIER_LSHIFT.  If
  23.       qualifier is 0, the function will return the item identified by
  24.       Intuition (if indeed menuNumber corresponds to a valid menu item).  A
  25.       value of NIL will be returned if no valid menu item can be identified.
  26.  
  27.     INPUTS
  28.       menuStrip = a pointer to the first menu in your menu strip
  29.       menuNumber = the value which contains the packed data that selects the
  30.          the menu and item (and sub-item).  Very simply, the rawkey code
  31.          gotten from an IDCMP_MENUPICK intuimessage
  32.       qualifier = the rawkey qualifier gotten from and IDCMP_MENUPICK
  33.          intuimessage
  34.  
  35.     RESULT
  36.       If menuNumber = MENUNULL or does not correspond to a valid menu item on
  37.       menuStrip, this function returns NIL; else this function returns the
  38.       address of the menu item specified by menuNumber and qualifier.
  39.  
  40.  *----------------------------------------------------------------------------*/
  41.  
  42. OPT MODULE
  43. OPT REG=5
  44.  
  45. MODULE 'intuition/intuition',
  46.        'devices/inputevent',
  47.        'other/lowerChar',
  48.        'other/upperChar'
  49.  
  50. EXPORT PROC qualifiedItemAddress(menuStrip:PTR TO menu, menuNumber, qualifier=0)
  51.   DEF item:PTR TO menuitem, origItem:PTR TO menuitem, subitem:PTR TO menuitem,
  52.       correctItem=NIL:PTR TO menuitem, commandChar, tChar=0
  53.   /*-- Get the vanilla item address: --*/
  54.   IF (origItem:=ItemAddress(menuStrip, menuNumber))=NIL THEN RETURN NIL
  55.   /*-------------------------------------------------------------------*
  56.     Qualifier will be:
  57.      - 0 if selected with the mouse;
  58.      - LCOMMAND unshifted, or RCOMMAND shifted if selected with hotkey
  59.     If Qualifier is 0, just return the one Intuition sent us.
  60.    *-------------------------------------------------------------------*/
  61.   IF qualifier=0 THEN RETURN origItem
  62.   /*-- Determine if we're looking for a shifted char or not: --*/
  63.   commandChar:=IF qualifier AND (IEQUALIFIER_RSHIFT OR IEQUALIFIER_LSHIFT) THEN
  64.                   upperChar(origItem.command) ELSE lowerChar(origItem.command)
  65.   /*-- Loop through menus, looking for our char: --*/
  66.   IF commandChar=origItem.command
  67.     correctItem:=origItem
  68.   ELSE
  69.     REPEAT  ->cycle thru menus
  70.       item:=menuStrip.firstitem
  71.       REPEAT  ->cycle thru items
  72.         subitem:=item.subitem
  73.         WHILE subitem<>NIL  ->cycle thru subitems
  74.           IF (tChar:=subitem.command)=commandChar
  75.             correctItem:=subitem
  76.             subitem:=NIL
  77.           ELSE
  78.             subitem:=subitem.nextitem
  79.           ENDIF
  80.         ENDWHILE
  81.         IF tChar=commandChar
  82.           item:=NIL
  83.         ELSEIF (tChar:=item.command)=commandChar
  84.           correctItem:=item
  85.           item:=NIL
  86.         ELSE
  87.           item:=item.nextitem
  88.         ENDIF
  89.       UNTIL item=NIL
  90.       menuStrip:=IF tChar=commandChar THEN NIL ELSE menuStrip.nextmenu
  91.     UNTIL menuStrip=NIL
  92.   ENDIF
  93.   /*-- Preserve multiple selections for a single menu event. -*/
  94.   IF correctItem THEN correctItem.nextselect:=origItem.nextselect
  95. ENDPROC correctItem
  96.   /* qualifiedItemAddress */
  97.